package map01;

import java.util.HashMap;
/*
*public boolean isEmpty():
*       如果map中没有键值对则返回true,有键值对返回false
*public boolean containsKey(Object key):
*       判断key在map集合中是否存在(依据hashCode方法和equals方法),存在则返回true,不存在则返回false
*public boolean containsValue(Object value):
*       判断value在map集合中是否存在(依据的是equals方法),存在则返回true,不存在则返回false
*public V remove(Object key):
*       根据指定的key(依据hashCode方法和equals方法),移除该键值对
*       如果该key在map中存在,则返回该key对应的value值
*       如果该key在map中不存在,则返回null
*
* */
public class HashMapDemo02 {
    public static void main(String[] args) {
        //method01();
        //method02();
        //method03();
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123, "张三");
        hm.put(456, "李四");
        hm.put(78, "王五");

        String str = hm.remove(78);//移除的是78="王五"键值对
        System.out.println(str);//王五
        System.out.println(hm);//{456=李四, 123=张三}

        System.out.println(hm.remove(13));//null
    }

    private static void method03() {
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123, "张三");
        hm.put(456, "李四");
        hm.put(78, "王五");

        System.out.println(hm.containsValue("李四"));//true
        System.out.println(hm.containsValue("马六"));//false
    }

    private static void method02() {
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123, "张三");
        hm.put(456, "李四");
        hm.put(78, "王五");

        System.out.println(hm.containsKey(123));//true
        System.out.println(hm.containsKey(13));//false
    }

    private static void method01() {
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123, "张三");
        hm.put(456, "李四");
        hm.put(78, "王五");

        System.out.println(hm.isEmpty());//false
        hm.clear();
        System.out.println(hm.isEmpty());//true
    }
}
